package com.xzy.b;

import org.springframework.context.annotation.AnnotationConfigApplicationContext;

/**
 * 说明：
 * 1、通过配置类中的@Bean注解定义Bean
 * 2、通过配置类创建Spring容器，依据Bean定义信息来创建Bean
 *
 * @author xzy
 * @date 2021/11/28 17:13
 */
public class Main {

    public static void main(String[] args) {
        method1();
        method2();
    }

    public static void method1() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext();
        applicationContext.register(StudentConfig.class);
        applicationContext.refresh();
        StudentService studentService = applicationContext.getBean(StudentService.class);
        System.out.println(studentService);
    }

    public static void method2() {
        AnnotationConfigApplicationContext applicationContext = new AnnotationConfigApplicationContext(StudentConfig.class);
        StudentService studentService = applicationContext.getBean(StudentService.class);
        System.out.println(studentService);
    }
}
